﻿package core.ui.options
{
    import core.event.*;
    import core.ui.controls.*;
    import flash.display.*;

    public class CropOptions extends Sprite implements IToolOptions
    {
        var ed:Tuyitu;
        var constraint:Dropdown;
        var tbw:NumberInput;
        var tbh:NumberInput;

        public function CropOptions(param1:Tuyitu)
        {
            this.ed = param1;
            var _loc_2:* = 10;
            var _loc_3:* = 15;
            _loc_2 = _loc_2 - 5;
            var _loc_4:* = new Literal("rm_constraint");
            _loc_4.x = _loc_2;
            _loc_4.y = 2;
            addChild(_loc_4);
            _loc_2 = _loc_2 + _loc_4.width;
            this.constraint = new Dropdown(120, 120);
            this.constraint.x = _loc_2;
            this.constraint.y = 2;
            this.constraint.addEventListener(SelectEvent.COMMAND, this.ConstraintChange, false, 1, true);
            this.constraint.AddItem(U.RM("rm_no_restriction"), "none", true);
            this.constraint.AddItem(U.RM("rm_aspect_ratio"), "ratio");
            this.constraint.AddItem(U.RM("rm_output_size"), "size");
            this.constraint.Bind();
            addChild(this.constraint);
            _loc_2 = _loc_2 + (this.constraint.width + _loc_3);
            var _loc_5:* = new BarSplit();
            _loc_5.x = _loc_2;
            addChild(_loc_5);
            _loc_2 = _loc_2 + (2 + _loc_3);
            _loc_2 = _loc_2 - 5;
            var _loc_6:* = new Literal("rm_width");
            _loc_6.x = _loc_2;
            _loc_6.y = 2;
            addChild(_loc_6);
            _loc_2 = _loc_2 + _loc_6.width;
            this.tbw = new NumberInput(40, 0, 1, 4000);
            this.tbw.x = _loc_2;
            this.tbw.y = 2;
            this.tbw.Disable();
            addChild(this.tbw);
            _loc_2 = _loc_2 + (this.tbw.width + _loc_3);
            var _loc_7:* = new Literal("rm_height");
            _loc_7.x = _loc_2;
            _loc_7.y = 2;
            addChild(_loc_7);
            _loc_2 = _loc_2 + _loc_7.width;
            this.tbh = new NumberInput(40, 0, 1, 4000);
            this.tbh.x = _loc_2;
            this.tbh.y = 2;
            this.tbh.Disable();
            addChild(this.tbh);
            _loc_2 = _loc_2 + (this.tbh.width + _loc_3);
            var _loc_8:* = new BarSplit();
            _loc_8.x = _loc_2;
            addChild(_loc_8);
            return;
        }// end function

        private function ConstraintChange(event:SelectEvent) : void
        {
            switch(event.val)
            {
                case "none":
                {
                    this.tbw.Disable();
                    this.tbh.Disable();
                    break;
                }
                case "ratio":
                {
                    this.tbw.Disable(false);
                    this.tbh.Disable(false);
                    this.tbw.value = 1;
                    this.tbh.value = 1;
                    break;
                }
                case "size":
                {
                    this.tbw.Disable(false);
                    this.tbh.Disable(false);
                    if (this.ed.canvas)
                    {
                        this.tbw.value = this.ed.canvas.dw;
                        this.tbh.value = this.ed.canvas.dh;
                    }
                    else
                    {
                        this.tbw.value = 640;
                        this.tbh.value = 480;
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function Lock() : void
        {
            this.constraint.Disable();
            this.tbw.Disable();
            this.tbh.Disable();
            return;
        }// end function

        public function Unlock() : void
        {
            this.constraint.Disable(false);
            if (this.constraint.value != "none")
            {
                this.tbw.Disable(false);
                this.tbh.Disable(false);
            }
            return;
        }// end function

        public function get options() : Object
        {
            return {constraint:this.constraint.value, width:this.tbw.value, height:this.tbh.value};
        }// end function

    }
}
